package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.Bean;
import com.sgb.kjwl.model.entity.enterprise.NeedEntity;
import com.sgb.kjwl.view.ui.fragment.enterprise.NeedChangeFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 作者:张磊
 * 日期:2020/12/21 0021
 * 说明:需求大厅
 */

public class NeedChangeModel extends BaseViewModel {
    private NeedChangeFragment mFragment;

    public NeedChangeModel(NeedChangeFragment fragment) {
        this.mFragment = fragment;
    }

    // 获取商标类型选项
    public void getTrademarkTypeOption() {
        DialogHelper.showProgressDialog(mFragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getNeedAPI().getTrademarkTypeOption().enqueue(new Callback<BaseEntity<List<Bean>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<Bean>>> call, Response<BaseEntity<List<Bean>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() != null) {
                    mFragment.getTrademarkTypeOption(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<Bean>>> call, Throwable t) {
                MToast.showToast(mFragment.getActivity(), t.getMessage());
            }
        });
    }

    // 获取所有版权
    public void getAllQualification() {
        DialogHelper.showProgressDialog(mFragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getNeedAPI().getAllQualification().enqueue(new Callback<BaseEntity<List<Bean>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<Bean>>> call, Response<BaseEntity<List<Bean>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() != null) {
                    mFragment.getAllQualification(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<Bean>>> call, Throwable t) {
                MToast.showToast(mFragment.getActivity(), t.getMessage());
            }
        });
    }

    // 获取领域分类
    public void getAllCopyright() {
        DialogHelper.showProgressDialog(mFragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getNeedAPI().getAllCopyright().enqueue(new Callback<BaseEntity<List<Bean>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<Bean>>> call, Response<BaseEntity<List<Bean>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() != null) {
                    mFragment.getAllCopyright(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<Bean>>> call, Throwable t) {
                MToast.showToast(mFragment.getActivity(), t.getMessage());
            }
        });
    }

    // 行业分类
    public void getAllSserviceCategory() {
        DialogHelper.showProgressDialog(mFragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getNeedAPI().getAllSserviceCategory().enqueue(new Callback<BaseEntity<List<Bean>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<Bean>>> call, Response<BaseEntity<List<Bean>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() != null) {
                    mFragment.getAllSserviceCategory(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<Bean>>> call, Throwable t) {
                MToast.showToast(mFragment.getActivity(), t.getMessage());
            }
        });
    }

    // 专利类型
    public void getPatentTypeOption() {
        DialogHelper.showProgressDialog(mFragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getNeedAPI().getPatentTypeOption().enqueue(new Callback<BaseEntity<List<Bean>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<Bean>>> call, Response<BaseEntity<List<Bean>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() != null) {
                    mFragment.getPatentTypeOption(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<Bean>>> call, Throwable t) {
                MToast.showToast(mFragment.getActivity(), t.getMessage());
            }
        });
    }

    // 需求大厅列表
    public void getDemandHallList(Map map) {
        DialogHelper.showProgressDialog(mFragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getNeedAPI().getDemandHallList(map).enqueue(new Callback<BaseEntity<NeedEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<NeedEntity>> call, Response<BaseEntity<NeedEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mFragment.getDemandHallList(response.body().getData().list);
                } else {
                    MToast.showToast(mFragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<NeedEntity>> call, Throwable t) {
                MToast.showToast(mFragment.getActivity(), t.getMessage());
            }
        });
    }
}
